#!/bin/sh
set -e

REPO="oscstudio/gitee-lfs-multipart-uploader"
VERSION="1.0.4"
BASE_URL="https://gitee.com/${REPO}/releases/download/${VERSION}"

# 检测系统和架构
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case "$ARCH" in
  x86_64) ARCH="amd64" ;;
  aarch64 | arm64) ARCH="arm64" ;;
  *) echo "❌ 暂不支持的架构: $ARCH"; exit 1 ;;
esac

# 组合二进制文件名
FILENAME="multipart-transfer-${OS}-${ARCH}"

# 下载
echo "⬇️ 正在下载 ${FILENAME} ..."
curl -L -o /tmp/multipart-transfer "$BASE_URL/$FILENAME"

echo "⚙️ 设置运行权限"
chmod +x /tmp/multipart-transfer

# 安装
echo "⚙️ 安装到 /usr/local/bin (需要sudo权限)"
sudo mv /tmp/multipart-transfer /usr/local/bin/

# 验证
echo "✅ 安装完成"
multipart-transfer --version || echo "请检查是否安装成功"
